﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Neat;
using Neat.GUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RattlerRace
{
    public class GameResultScreen : Screen
    {
        private bool typeEnabled = true;

        public GameResultScreen(NeatGame Game)
            : base(Game)
        {
        }

        Label userField;
        Button mybutton;
        Button resetButton;
        public override void Initialize()
        {
            base.Initialize();
            Label hello = Form.NewControl("hello", new Label()) as Label;
            hello.Caption = "Results";
            hello.Position = new Vector2(100, 100);
            hello.ForeColor = Color.White;

            mybutton = Form.NewControl("mybutton", new Button()) as Button;
            mybutton.Caption = "Main menu";

            mybutton.ForeColor = Color.White;
            mybutton.HoverTintColor = Color.Green;
            mybutton.Size = new Vector2(400, 70);
            mybutton.OnPress = mybutton_OnPress;

            resetButton = Form.NewControl("resetButton", new Button()) as Button;
            resetButton.Caption = "Reset";

            resetButton.ForeColor = Color.White;
            resetButton.HoverTintColor = Color.Green;
            resetButton.Size = new Vector2(400, 70);
            resetButton.OnPress = resetButton_OnPress;

            Form.HasMouse = true;
            base.game.ShowMouse = true;
        }

        void userField_OnPress()
        {
            typeEnabled = true;
        }

        void mybutton_OnPress()
        {
            base.game.Console.Run("e_show mainmenu");
        }

        void resetButton_OnPress()
        {
            Game1.Results.Clear();
            Activate();
        }

        public override void Activate()
        {
            base.Activate();
            Label resultLabel;
            int index = 1;
            Vector2 position = new Vector2(0,0);
            foreach (GameStats gameStat in Game1.Results.OrderByDescending(o => o.Score).ToList())
            {
                resultLabel = Form.NewControl("resultLabel" + index, new Label()) as Label;
                resultLabel.Caption = index + ". " + gameStat.PlayerName + "["+gameStat.Score+"]";
                resultLabel.Position = position = new Vector2(100, 100 + (index * 20));
                resultLabel.ForeColor = Color.White;
                index++;
            }
            mybutton.Position = new Vector2(100, position.Y+50);
            resetButton.Position = new Vector2(100, position.Y + 120);
        }
    }
}
